const labelService = require("../service/label.service");


class LabelController {
    async create(ctx, next) {

        const { name } = ctx.request.body;

        const res = await labelService.select(name);
        if (res.length !== 0) {
            const error = new Error("该标签已存在");
            return ctx.app.emit('error', error, ctx);
        }

        const result = await labelService.create(name);
        ctx.body = result;
    }

    async list(ctx, next) {
        const { limit, offset } = ctx.query;
        const result = await labelService.getLabels(limit, offset);
        ctx.body = result;
    }
}

module.exports = new LabelController();